﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SilverlightBridge.Web;
using SilverlightDesktopCore.DAL;

namespace SilverlightDesktopCore.AuthenticationService
{
    public class AuthenticationService : IAuthenticationService
    {
        #region IAuthenticationService Members
        public bool ValidateUser(string username, string password, string customCredential)
        {
            switch (HttpContext.Current.User.Identity.AuthenticationType)
            {
                case "Forms":
                    SilverlightDesktopDAL SilverlightDesktopDAL = new SilverlightDesktopDAL();

                    //  Get the SilverlightKey
                    var SilverlightUser = (from ASilverlightDesktopUser in SilverlightDesktopDAL.SilverlightDesktopUsers
                                           where ASilverlightDesktopUser.UserName == username
                                            && ASilverlightDesktopUser.Password == password
                                            && ASilverlightDesktopUser.Active == true
                                           select ASilverlightDesktopUser).FirstOrDefault();

                    return (SilverlightUser != null ? true : false);
                case "Windows":
                    return HttpContext.Current.User.Identity.IsAuthenticated;
                default:
                    return false;
            }
        }
        #endregion
    }
}
